const GetUser = {
  methods: {
    getUser() {
      this.$http(this.$API.getUserInfo, {}).then(res => {
        if (res) {
          this.$store.commit("saveUser", res);
        }
      });
    }
  }
};
const Privilege = {
  methods: {
    privilege(pageId, actions) {
      let user = this.$store.state.user;
      if (!user || !user.pages) {
        return false;
      }
      if (user.admin == 1 || user.admin == 5) {
        return true;
      }
      let res = user.pages.filter(e => e.pageId === pageId);
      return !actions ? true : res.some(e => e.actions && e.actions.includes(actions))
    }
  }
};

export { GetUser, Privilege };
